//
//  main.m
//  OC6_数组&字典作业2
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
//#import "Color.h"
#import "ColorManager.h"

int main(int argc, const char * argv[]) {

    NSString *filePath = @"/Users/dllo/Desktop/DLS151034/OC6_字典&集合/OC6_字典&集合课后作业/OC6_数组&字典作业2/OC6_数组&字典作业2/File";
    NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
//    NSLog(@"%@", str);
    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSLog(@"%@", arr);
    
    // 1, 取出所有的key，value 存到字典dic中
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (NSInteger i = 0; i < arr.count; i++) {
        NSArray *temp = [[arr objectAtIndex:i] componentsSeparatedByString:@" #"];
        [dic setValue:[temp objectAtIndex:1] forKey:[temp objectAtIndex:0]];
    }
//    NSLog(@"%@", dic.allKeys);
    
    
    // 2, 按key 升序排序
    
    NSArray *key = [[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
//    NSLog(@"%@", key);
    
    
    
    // 3, 取出所有的value,按照排序后的key排列.
    
    NSMutableArray *value = [NSMutableArray array];
    for (NSInteger i = 0; i < key.count; i++) {
        //        NSLog(@"%@", [dic objectForKey:[key objectAtIndex:i]]);     // 打印出按照key排序后的value
        [value addObject:[dic objectForKey:[key objectAtIndex:i]]];  // 赋值value
    
    }
    
    
    
    // 定义新字典存排序后的value key
//    NSMutableDictionary *newDic = [NSMutableDictionary dictionary];
//
//    for (NSInteger i = 0; i < key.count; i++) {
//        [newDic setObject:[dic objectForKey:[key objectAtIndex:i]] forKey:key];
//    }

    
    // 4,新字典管理颜色
    
    ColorManager *colorList = [[ColorManager alloc] init];

    for (NSInteger i = 0; i < key.count; i++) {
//        NSString *str = [value objectAtIndex:i];
        [colorList addColor: [key objectAtIndex:i] colorvalue:[value objectAtIndex:i]];
    }
    
    // 选取字符打印查看
    
//    [colorList test:@"A"];
    
    
    
    
    
    return 0;
}
